import { CmdConfType } from '@common'
import { BaseModelTreeNodeType } from '@renderer/types'

export type CmdConfTreeNodeType = CmdConfType &
  BaseModelTreeNodeType & {
    children?: CmdConfTreeNodeType[]
  }

export type CmdConfTreeType = CmdConfTreeNodeType[]

export const useCmdConfStore = defineStore('cmdConfStore', () => {
  const { getMap, getList, getTree, getDirTree, getTreeMapAll, getTreeMap, load } =
    genAndLoadConfStatus(api.findCmdConfs) as {
      getMap: () => Record<string, CmdConfType>
      getList: () => CmdConfTreeType
      getTree: () => CmdConfTreeType
      getDirTree: () => CmdConfTreeType
      getTreeMapAll: () => Record<string, CmdConfTreeNodeType>
      getTreeMap: () => Record<string, CmdConfTreeNodeType>
      load: () => Promise<void>
    }

  return {
    getMap,
    getList,
    getTree,
    getDirTree,
    getTreeMapAll,
    getTreeMap,
    load
  }
})
